import logging

import requests
from fastapi import APIRouter, Depends
from db.pydantic.request.sms import UpdatePhoneRequest, UpdateGroupRequest, CreateGroupRequest, SendSmsPhoneRequest, \
    SendSmsGroupRequest
from services.sms_service import get_SMSService, SMSService
from utils.result import Result

logger = logging.getLogger("app.sms")
router = APIRouter()



@router.post("/qw/sms/send")
async def router_sms_send(send_req:SendSmsPhoneRequest,sms_service: SMSService = Depends(get_SMSService)):
    """
    发送短信 --以手机号码为单位发送
        支持一次发送多个联系人，（发送多个联系人需要对手机号码recipient参数进行用,进行区分）
            实例：["15212602132","15655841102",...]
    """
    return await sms_service.send_by_phone(send_req)



@router.post("/sms/send")
async def sms_send(request: dict):
    mobile = request.get("mobile")
    api_url = "https://openapi.siss.cloud/open/api/send"
    content = "【意数未来】合肥独家新产品新政策，专注于企业及个人信用管理规划，添加企业微信咨询 iqnn.com.cn/9THPF 拒收请回复R"
    params = {
            "accessKey": "GajW7Athy6we2aSN",
            "accessSecret": "qc6ZTxNOXaAD7gTutWNxnhS48HXMy7tV",
            "mobile": mobile,
            "content": content
    }
    res = requests.post(api_url, json=params)
    logger.info(res.json())
    return "ok"

# @router.post("/qw/sms/send/status")
# async def sms_send_status(mobile: str,status:str):


@router.post("/sms/update")
async def sms_list(request: dict):
    api_url = "https://openapi.siss.cloud/open/api/query/report"
    params = {
            "accessKey": "GajW7Athy6we2aSN",
            "accessSecret": "qc6ZTxNOXaAD7gTutWNxnhS48HXMy7tV"
    }
    res = requests.post(api_url, json=params)
    logger.info(res.json())
    return Result.success("ok")
